<%@page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Your scrum stories</title>

    <script type="text/javascript">

        function checkSortChanges() {

        }

        var myClick = function (event) {
            var location = $(event.target).children("a")[0].href;
            window.location = location;
        };

        $(function() {
            $("#sortable").sortable();
            $("#sortable").disableSelection();
            $("#sortable").bind('sortupdate', function(event, ui) {
                //window.alert($("#sortable").sortable('serialize'));
//                var ids = $.makeArray(
//                        $("#sortable").find("li").map(function() {
//                            return this.id.match(/\w+_(\d+)/i)[1];
//                        }));
//                window.alert(ids);
//            });
            //            $("#sortable").bind('sortchange', function(event, ui) {
            //                window.alert($("#sortable").sortable('serialize'));
                var ids = $("#sortable").sortable('serialize').toString();
                $.post('/story/reorder',{ids: ids},function() {
                    alert('done');
                });
            });
            $("#sortable li span.listItemAdd").addClass("ui-icon ui-icon-circle-plus").click(myClick);
        });
    </script>
</head>
<body>
<div id="list-of-stories">
    <ul id="sortable">
        <c:forEach items="${stories}" var="story">
            <li id="story_${story.id}" class="ui-state-default"><span
                    class="listItemLabel">${story.name}</span><span
                    class="listItemAdd"><a
                    href="/story/${story.id}/task/form" title="add task">add</a></span><span
                    class="listItemChilds">tasks(${story.numberOfTasks})</span></li>
        </c:forEach>
    </ul>
</div>
</body>
</html>